<?php
/**
 * 上传控制
 */

namespace app\common\controller;

use think\Validate;
use think\Request;

class Upload 
{
    /**
     * 图片/文件验证规则
     * @var array
     */
    protected $validateRule = [
        'image' => [
            'size' => 5242880, //5M
            'ext'  => 'jpg,jpeg,png,gif,bmp'
        ],
        'file' => [
            'size' =>  5242880,
            'ext'  => 'pdf,txt,doc,docx,xls,xlsx'
        ]
    ];
    /**
     * 上传图片
     * @param  string $filename 上传的字段名
     * @return [type]           [description]
     */
    public function image($filename = 'file')
    {
        $file = Request::instance()->file($filename);
        $info = $file->validate($this->validateRule['image'])->move(ROOT_PATH.'public'.DS.'uploads');
        return $info ? $info : $file->getError();
    }
}